/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import com.google.gson.Gson;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Client;
import model.Flight;
import model.Receipt;

/**
 *
 * @author Jorge
 */
public class ConcreteMessagingService extends ContreteService implements MessagingService{

    public ConcreteMessagingService() {
        super("http://localhost:8084/WebServiceFlightBooking/webresources/messaging");
    }
    
    

    @Override
    public String sendMessage(Receipt receipt, Client client) {
        try {
            URL recurso = new URL(urlBase + "?receiptCode="+receipt.getCode()+"&BookingCode="+receipt.getBooking().getBookingCode()
                    +"&clientName="+client.getName());
            HttpURLConnection conexao = (HttpURLConnection) recurso.openConnection();
            conexao.setRequestMethod("GET");
            conexao.setDoOutput(true);
            conexao.connect();

            String res = lerInputStream(conexao.getInputStream());
            conexao.disconnect();
            
            String message = new Gson().fromJson(res, String.class);
            
            return message;
        } catch (IOException ex) {
            Logger.getLogger(ConcreteDatabaseService.class.getName()).log(Level.SEVERE, null, ex);
            
        }
        return null;

    }
    
}
